<?php View::render('admin/layouts/meta');?>
<body>
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页
    <span class="c-gray en">&gt;</span> 优惠券管理
    <span class="c-gray en">&gt;</span> 优惠券列表
    <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
        <i class="Hui-iconfont">&#xe68f;</i>
    </a>
</nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            <a href="javascript:;" onclick="formAlert('发放优惠券','<?php echo Router::getBaseUrl(); ?>/admin_coupon/editusercoupon', '80%','80%')" class="btn btn-primary radius">
                <i class="Hui-iconfont">&#xe600;</i> 发放优惠券
            </a>
        </span>
        <span class="r">共有数据：<strong><?php echo count($list); ?></strong> 条</span>
    </div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="50">ID</th>
                <th width="">领取用户UID</th>
                <th width="150">优惠券名称</th>
                <th width="">优惠金额</th>
                <th width="">最低消费金额</th>
				<th width="">状态</th>
                <th width="">开始时间</th>
                <th width="">结束时间</th>
                <th width="100">操作</th>
			</tr>
		</thead>
		<tbody>
            <?php if ($list) {
	foreach ($list as $info) {?>
			<tr class="text-c">
				<td><?php echo $info['id']; ?></td>
                <td><?php echo $info['uid']; ?></td>
                <td><?php echo $info['coupon_name']; ?></td>
                <td><?php echo $info['type'] == 1 ? $info['price'] . '元' : $info['price'] . '折'; ?></td>
                <td><?php echo $info['min_price']; ?></td>
                <td><?php echo $info['status'] == 1 ? '已使用' : $info['status'] == 2 ? '已过期' : '未使用'; ?></td>
                <td><?php echo date('Y-m-d H:i:s', $info['s_time']); ?></td>
                <td><?php echo date('Y-m-d H:i:s', $info['e_time']); ?></td>
				<td class="td-manage">
                    <a href="javascript:;" rel="<?php echo $info['id']; ?>" style="text-decoration:none"  class="ml-5 j_del">删除</a>
                </td>
			</tr>
            <?php }}?>
		</tbody>
	</table>
	</div>
</div>
</body>
<?php View::render('admin/layouts/footer');?>
<script type="text/javascript">
$(function(){
    window.formAlert = function(title, url, w, h) {
        layer.open({
            type: 2,
            title: title,
            area: [w, h],
            content: url,
            end: function(){
               window.location.href=location.href;
            }
          });
    }
    $('.j_del').click(function(){
        var id = $(this).attr('rel');
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_coupon/deleteusercoupon', {coupon_id:id}, function (result) {
                if (result.status == 200) {
                    layer.msg(result.msg, {
                        icon: 1,
                        skin: 'u-msg',
                        time: 1800,
                    },function() {
                        window.location.href = location.href;
                        return true;
                    });
                }else{
                    layer.msg(result.msg, {
                        icon: 0,
                        skin: 'u-msg',
                        time: 2200,
                    });
                }
            }, 'json');
        return;
    });
});
</script>
</html>